<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<body class="gray-bg">
    <!-- 客户管理页面 -->
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul >
							<li>
								用户手机号：<input type="text" name="pHONE"/>
							</li>
							<li>
								用户名称：<input type="text" name="merchantCnName"/>
							</li>
							<!-- <li>
								代理编号：<input type="text" name="agentNo"/>
							</li> -->
							<li>
								代理名称：<input type="text" id="agentName" name="agentName"/>
										<input  type="hidden" id="agentNameList" value=""/><br>
							</li>
							<li>
								推荐人电话：<input type="text" id="parentPhone" name="parentPhone"/>
							</li>
							
							<!-- <li>
								代理关系：<select name="direct" th:with="type=${@dict.getType('agent_direct')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>  -->
							<li>
								用户级别：<select name="lEVEL" th:with="type=${@dict.getType('merchant_level')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li> 
							<li>
								实名认证
								<select name="isActive" >
									<option value="">全部</option>
									<option value="01">已认证</option>
									<option value="02">未认证</option>
									<option value="03">已绑卡</option>
								</select>
							</li> 
							
							<li class="select-time">
								<label>创建时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" id="btnSearch"  onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<!-- 修改用户备注 -->
	 <div id="dialog" class="modal fade text-center">
		  <div class="modal-dialog" style="display: inline-block; width: auto;">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		        <h4 class="modal-title">修改备注</h4>
		      </div>
		      <div class="modal-body">
		       	备注名称:<input id="remark" placeholder="请输入用户备注名称">
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <button onclick="submitEdit()" type="button" class="btn btn-primary">提交</button>
		      </div>
		    </div>
		  </div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
    var level = [[${@dict.getType('merchant_level')}]];
    var detailFlag = [[${@permission.hasPermi('system:hatchetMerchant:detail')}]];
    var direct_type = [[${@dict.getType('agent_direct')}]];
    var prefix = ctx + "system/hatchetMerchantForDLS";
	var tableUrl = prefix + "/list";
	var agentNameList = [];
    $(function() {
    	agents();
     	//代理商名称自动补全
     	$("#agentName").autocomplete({
    		source: agentNameList
    	});
        var options = {
            url: tableUrl,
         /*    createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove", */
            detailUrl: prefix + "/detailForDLS/{id}",
			exportUrl: prefix + "/export",
            modalName: "用户列",
			search: false,
	        showExport: false,
            columns: [{
	            checkbox: true
	        },
			{
				field : 'id', 
				title : '',
				visible: false
			},
			{
				field : 'merchantNo', 
				title : '用户编号',
				sortable: true
			},
			/* {
				field : 'direct', 
				title : '用户关系',
				sortable: false
			}, */
			{
				field : 'merchantCnName', 
				 title : '用户名称',
			     align: 'center',
	             formatter: function(value, row, index) {
		            	if(row.agentSalesName==null){
		            		return value;
		            	} else {
		            		return row.agentSalesName;
		            	}
		            }
			},
			/* {
				field : 'agentNo', 
				title : '代理商编号',
				sortable: false
			}, */
			{
				field : 'agentName', 
				title : '代理名称',
				sortable: false
			},
			
			{
				field : 'parentName', 
				title : '推荐人',
				sortable: false
			},
			{
				field : 'parentPhone', 
				title : '推荐人号码',
				sortable: false
			},
			{
				field : 'phone', 
				title : '手机号',
				sortable: false
			},
			{
				field : 'level', 
				title : '用户等级',
				align : 'left',
				formatter: function(value, row, index) {
            		return $.table.selectDictLabel(level, value);
            	}
			},
			{
				field : 'liveness', 
				title : '活跃度',
				sortable: false
			},
			{
				field : 'submitExamineTime', 
				title : '升级黄金会员时间',
				sortable: false
			},
			{
				field : 'submitReexamineTime', 
				title : '升级经理时间',
				sortable: false
			}, 
			{
				field : 'bankAccount', 
				title : '银行卡号',
				sortable: false
			},
			{
				field : 'idCardNumber', 
				title : '身份证',
				sortable: false
			},
			
		 	{
				field : 'upgradeCodeNum', 
				title : '升级码数',
				sortable: false
			}, 
			{
				field : 'createTime', 
				title : '创建时间',
				sortable: true
			} ,
			
	        {
	            title: '操作',
	            align: 'center',
	            formatter: function(value, row, index) {
	            	var actions = [];
	            	//借用moneyType 设置标识 这是 高级经纪人可以修改用户备注
	            	if(row.moneyType=="y"){
	            		actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="#" onclick="editRemark(\'' + row.id + '\')">修改备注</a> ');
	            	} else {
	            		actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="#" onclick="$.operate.detail(\'' + row.id + '\')">查看详情</a> ');
	            	}
					return actions.join('');
	            }
	        } ]
        };
        $.table.init(options);
        
        
        //查找代理商下面的所有代理商
   		function agents(){
      		var array=[];
  			$.ajax({
  				url: ctx+"system/hatchetAgent/getAgentAllForDLS",
  				async:false,
  				type:"POST",
  				data:{},
  				success: function(result) {
  					$.each(result, function(i,v) {
  						if (v.agentName != null && v.agentName != undefined) {
  							agentNameList.push(v.agentName);
  							var arrays = {};
  							arrays.value = v.agentName;
  							arrays.id = v.id;
  							array.push(arrays);
  						}
  					});
  				}
  			});
  			return array;
      	} 
          
    });
    var merId ="";
    function editRemark(id){
    	merId = id;
    	$("#remark").val("");
    	//弹出模态框准备输入备注名称
		$('#dialog').modal('show');
    	
    }
    
    function submitEdit(){
    	var remark = $("#remark").val();
    	if(remark==""){
    		 $.modal.alertError("用户备注不能为空");
			 return;
    	}
    	$.ajax({
				url: prefix+"/edit",
				type:"POST",
				data:{
					"agentSalesName":remark,
					"iD":merId
				},
				success: function(result) {
					if(result.status=="FAIL"){
						 $.modal.alertError(result.msg);
						 return;
					}else {
						$('#dialog').modal('hide');
						$.modal.msgSuccess(result.msg);
						$('#btnSearch').click();
					}
				}
			});
    	}
    
    </script>
</body>
</html>